package com.zb_study.Homework07;


public class homework07 {
    public static void main(String[] args) {
        Teacher[] teachers = new Teacher[2];
        teachers[0] = new Teacher("张飞", 30, '男', 5);
        teachers[1] = new Teacher("jack", 5, '男', 10);
        // teachers[0].printInfo();


        Student[] students = new Student[2];
        students[0] = new Student("小明", 15, '男', "00023102");
        students[1] = new Student("小美", 18, '女', "00020100");
        // students[0].printInfo();

        Person temp = null;
        Person[] people = new Person[4];
        people[0] = teachers[0];
        people[1] = teachers[1];
        people[2] = students[0];
        people[3] = students[1];

        for (int i = 0; i < people.length; i++) {
            for (int j = 0; j < people.length - i - 1; j++) {
                if (people[j].getAge() < people[j + 1].getAge()) {
                    temp = people[j];
                    people[j] = people[j + 1];
                    people[j + 1] = temp;
                }
            }
        }

        for (int i = 0; i < people.length; i++) {
            System.out.println(people[i]);
        }
        homework07 h = new homework07();
        for (int i = 0; i < people.length; i++) {

            h.test(people[i]);
        }


    }
    public void test(Person p) {
        if(p instanceof Teacher) {
            ((Teacher) p).teach();
        } else if(p instanceof Student) {
            ((Student) p).study();
        } else {
            System.out.println("do nothing...");
        }
    }

}
